package nc.bs.pub.action;

import java.util.Hashtable;

import nc.bc.cmp.itf.IAttchementFileService;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.pub.compiler.AbstractCompiler2;
import nc.cmp.pub.exception.ExceptionHandler;
import nc.vo.cmp.bill.BillAggVO;
import nc.vo.cmp.bill.CommonContext;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pub.BusinessException;
import nc.vo.pub.compiler.PfParameterVO;
import nc.vo.pub.lang.UFBoolean;

public class N_F5_SAVEBASE extends AbstractCompiler2 {
	private final Hashtable<String, Object> m_methodReturnHas = new Hashtable();
	private Hashtable<String, Object> m_keyHas = null;

	public Object runComClass(PfParameterVO paraVo) throws BusinessException {
		try {
			if (paraVo.m_preValueVos == null) {
				return null;
			}
			this.m_tmpVo = paraVo;

			setParameter("context", paraVo.m_preValueVos);

			InvocationInfoProxy.getInstance().setProperty("SaveCommit", UFBoolean.TRUE.toString());

			Object obj = runClass("nc.bs.cmp.bill.actions.PayBillBatchSaveBSAction", "insertVOs",
					"&context:nc.vo.pub.AggregatedValueObject[]", paraVo, this.m_keyHas);

			if (obj != null) {
				this.m_methodReturnHas.put("insertVOs", obj);
			}
			this.uploadFile(obj);
			return obj;
		} catch (Exception ex) {
			throw ExceptionHandler.handleException(getClass(), ex);
		}
	}
	
	/** 
	 * modify wy at 2024年4月11日
	 * 附件上传  
	 * @param obj
	 * @throws BusinessException
	 */
	protected void uploadFile(Object obj) throws BusinessException{
		BillAggVO[] aggvos = null;
		try {
			if(obj instanceof nc.vo.cmp.bill.BillAggVO[]) {
				aggvos = (BillAggVO[])obj;
			}else {
				BillAggVO aggvo = (BillAggVO)obj;
				aggvos = new  BillAggVO[] {aggvo};
			}
			IAttchementFileService service = NCLocator.getInstance().lookup(IAttchementFileService.class);
			service.attachmentUploadFDK(aggvos);
		}catch(BusinessException e) {
			throw new BusinessException("附件上传处理异常:"+e.getMessage());
		}
		
	}
	public String getCodeRemark() {
		return NCLangRes4VoTransl.getNCLangRes().getStrByID("3607mng_0", "03607mng-0360");
	}

	protected void setParameter(String key, Object val) {
		if (this.m_keyHas == null) {
			this.m_keyHas = new Hashtable();
		}
		if (val != null)
			this.m_keyHas.put(key, val);
	}

	protected void setContext(CommonContext context) throws BusinessException {
	}
}